<template lang="html">

  <div class="wrap">
    <ul class="something" v-if='counts'>
      <li v-for="(k,i) in counts">
          <div class="something-left" @click="toggle">
            <label class="true" :class="{false:!k.choseBool}">
              <input type="checkbox" v-model="k.choseBool">
            </label>
          </div>
          <div class="something-middle">
            <img :src="k.goods_img">
          </div>
          <div class="something-right">
            <p>{{k.goods_name}}</p>
            <p style="color:rgb(199, 108, 28)">数量：{{k.goods_number}}</p>
            <p>售价：{{k.shop_price}}元</p>
            <div class="something-right-bottom" @click="cut(i)">
              <span></span>
            </div>
          </div>
      </li>
    </ul>
    <footer class="footer">
      <div class="footer-result">
        <p>共{{this.counts.length}}件 金额：</p>
        <p><span>{{applyAll}} </span>元</p>
      </div>
      <router-link :to="{path: '/home'}" class="footer-goon" >
        继续购物
      </router-link>
      <a class="footer-pay" @click="goPay">
        去结算
      </a>
    </footer>
  </div>
</template>

<script>
// 提示登录组件
import Util from '../../util/common'
export default {
  props: ['counts'],
  mounted() {
    // 初始化先获取购物车商品列表 否则 页面刷新出Bug
    if (this.$store.state.detail.carList == "") {
      this.$store.commit('RESET_CARLIST')
     };
  },
  computed: {
    applyAll () {
      let number = 0
      this.counts.forEach(item => {
        number += (+item.shop_price * +item.goods_number)
      })
      console.log(number)
      return number
    }
  },
  methods: {
    goPay () {

    },
    cut(i){
      let newCarList= [];
      for (let k = 0; k < this.carList.length; k++) {
          if(k!==i) {
            newCarList.push(this.carList[k])
          }
      }
      //点击垃圾桶 把商品数量count-1
         this.$store.dispatch('setLocalCount',false);
         this.$store.dispatch('cutCarList',newCarList);
    },
    toggle() {
      setTimeout(() => {
          // 每点击一下都会改变choseBool的布尔值,所以要重置数组
          this.$store.dispatch('cutCarList',this.carList)
      }, 0);
    }
  }
}
</script>

<style lang="less" scoped>
@import '../../assets/fz.less';
.wrap {
    width: 100%;
    .something {
        width: 100%;
        > li {
            display: -ms-flex;
            display: -webkit-box;
            display: -ms-flexbox;
            display: flex;
            -webkit-box-align: center;
            -ms-flex-align: center;
            align-items: center;
            padding: 4vw 2vw;
            position: relative;
            height: 26vw;
            .bd();
            .something-left {
                -ms-flex: 2;
                -webkit-box-flex: 2;
                flex: 2;

                label {
                    float: left;
                    background: url("../../assets/car/images/t.svg") no-repeat center center/50% 50%;
                    input {
                        height: 14vw;
                        width: 14vw;
                        opacity: 0;
                        filter: alpha(opacity=0);
                    }
                }
                .false {
                    background: url("../../assets/car/images/f.svg") no-repeat center center /50% 50%!important;
                }

            }
            .something-middle {
                -ms-flex: 3;
                -webkit-box-flex: 3;
                flex: 3;
                height: 26vw;
                padding-left: 2vw;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                img {
                    display: block;
                    width: 100%;
                    height: 100%;
                }
            }
            .something-right {
                -ms-flex: 7;
                -webkit-box-flex: 7;
                flex: 7;
                height: 100%;
                display: -ms-flex;
                display: -webkit-box;
                display: -ms-flexbox;
                display: flex;
                -webkit-box-orient: vertical;
                -webkit-box-direction: normal;
                -ms-flex-flow: column wrap;
                flex-flow: column wrap;
                -webkit-box-pack: justify;
                -ms-flex-pack: justify;
                justify-content: space-between;
                padding-left: 6vw;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                p {
                    overflow: hidden;
                    text-overflow: ellipsis;
                    display: -webkit-box;
                    -webkit-line-clamp: 2;
                    -webkit-box-orient: vertical;
                    .fz(font-size,26);
                }
                p:last-of-type {
                    .fz(font-size,22);
                    color: rgb(168, 168, 168);
                }
                .something-right-bottom {

                    > div {
                        display: -ms-flex;
                        display: -webkit-box;
                        display: -ms-flexbox;
                        display: flex;
                        -webkit-box-align: center;
                        -ms-flex-align: center;
                        align-items: center;
                        input {
                            width: 6vw;
                            text-align: center;
                        }

                        span {
                            height: 7vw;
                            line-height: 7vw;
                            width: 8vw;
                            display: inline-block;
                            border: 0.2vw solid #f1f1f1;
                            border-radius: 1vw;
                            text-align: center;
                            font-size: 20px;
                            cursor: pointer;
                        }
                    }
                    > span {
                        position: absolute;
                        right: 0;
                        bottom: 0;
                        width: 13vw;
                        height: 13vw;
                        background: url("../../assets/car/images/laji.svg") no-repeat center/50%;
                    }
                }
            }
        }
    }
    label,
    span {
        &:active {
            -webkit-transform: scale(1.3);
            transform: scale(1.3);
        }
    }
}
.footer {
  width: 100%;
  height: 16vw;
  display: -webkit-flex;
  display: -ms-flex;
  display: flex;
  align-items: center;
  position: fixed;
  bottom: 0;
  left: 0;
  background-color: #ffffff;
  .footer-result,a {
    -webkit-flex: 1;
    -ms-flex: 1;
    flex: 1;
    text-align: center;
  }
  .footer-result {
    p {
      .fz(font-size,24);
      color: #999;
    }
    p:last-of-type {
      padding: 1vw 0 0 1vw;
      span {
        color:@cl;
        .fz(font-size,42);
      }
    }
  }
  .footer-goon {
    background-color: #F4F4F4;
    line-height: 16vw;
  }

  .footer-pay {
    background-color: @cl;
    line-height: 16vw;
    color:#fff;
  }
}
</style>
